//
//  BaseViewController.m
//  winterTest
//
//  Created by wwinter on 15/11/10.
//  Copyright © 2015年 Wei Chuang Le ,Ltd. All rights reserved.
//

#import "BaseViewController.h"
#import "WDNavigationController.h"

@interface BaseViewController ()

@end

@implementation BaseViewController

#pragma mark -
#pragma mark - self cycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    NSString *VCStr = NSLocalizedString([NSString stringWithUTF8String:object_getClassName(self)], nil);
    // talkingData begin tarck
//    [TalkingData trackPageBegin:VCStr];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    
    NSString *VCStr = NSLocalizedString([NSString stringWithUTF8String:object_getClassName(self)], nil);
    // talkingData end track
//    [TalkingData trackPageEnd:VCStr];
}

#pragma mark -
#pragma mark - self method

- (void)tabBarItemClicked
{

}

#pragma mark -
#pragma mark - notification

+ (void)handleNotificationInfo:(NSDictionary *)userInfo applactionState:(UIApplicationState)applicationState
{

}

#pragma mark -
#pragma mark - present VC

+ (UIViewController *)presentingVC
{
    // 取出当前ViewController 所在的window
    UIWindow *window = [[UIApplication sharedApplication] keyWindow];
    if (UIWindowLevelNormal != window.windowLevel) {
        NSArray *windows = [[UIApplication sharedApplication] windows];
        for (UIWindow *aWindow in windows) {
            if (UIWindowLevelNormal == aWindow.windowLevel) {
                window = aWindow;
                break;
            }
        }
    }
    
    UIViewController *objViewController = window.rootViewController;
    
    // 取出带有 presented viewcontroller
    while (objViewController.presentedViewController) {
        objViewController = objViewController.presentedViewController;
    }
    
    // 取出带有导航 的 viewcontroller
    if ([objViewController isKindOfClass:[UINavigationController class]]) {
        objViewController = [(UINavigationController *)objViewController topViewController];
    }
    return objViewController;
}

+ (void)presentToVC:(UIViewController *)toViewController
{
    if (!toViewController) {
        return;
    }
    
    UINavigationController *nav = [[WDNavigationController alloc] initWithRootViewController:toViewController];
    toViewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"取消" style:UIBarButtonItemStylePlain target:toViewController action:@selector(dismissModalViewControllerAnimated:)];
    [[self presentingVC] presentViewController:nav animated:YES completion:nil];
}

+ (UIViewController *)analyseVCFromLinkStr:(NSString *)linkStr
{
    return nil;
}

+ (void)presentLinkStr:(NSString *)linkStr
{

}

@end
